#ifndef __PROTOCOL_H_
#define __PROTOCOL_H_

#include <QString>


/*
 *@Details: 全局变量和宏定义
 */
#define BGN_RESD_MSG	0x7B	//"{":起始符
#define END_RESD_MSG    0x7D  	//"}":结束符
/*数据发送解析式的宏定义*/
#define PROT_FULL_CMD   0x00
#define PROT_ZERO_LEN   0x00
#define PROT_FULL_DATA  0x00
#define PROT_FULL_CRC   0x00
#define DATA_TO_ASCII   0x30   //发送数据时数字到ASCII码的基数0

typedef enum{
    DEV_Warn = 'W',
    DEV_Mode = 'M',
    DEV_Beep = 'B',
    DEV_Temp = 'T',
    DEV_Humi = 'H'
}DEV;

typedef enum{
    CMD_WarnGain = 'G',
    CMD_WarnData = 'D',
    CMD_WarnOvrT = 'O',
    CMD_WarnLowT = 'L',
    CMD_WarnOvrH = 'V',
    CMD_WarnLowH = 'R',
}WarnCMD;


typedef enum{
    CMD_ModeGain = 'G',
    CMD_ModeData = 'D',
    CMD_ModeTemp = 'T',
    CMD_ModeHumi = 'H'
}ModeCMD;
typedef enum{
    CMD_BeepOn  = 'N',
    CMD_BeepOff = 'F'
}BeepCMD;
typedef enum{
    CMD_TempReal = 'R',
    CMD_TempMaxV = 'M',
    CMD_TempMaxA = 'A',
    CMD_TempMaxS = 'X',
    CMD_TempMinV = 'W',
    CMD_TempMinA = 'I',
    CMD_TempMinS = 'N'
}TempCMD;
typedef enum{
    CMD_HumiReal = 'R',
    CMD_HumiMaxV = 'M',
    CMD_HumiMaxA = 'A',
    CMD_HumiMaxS = 'X',
    CMD_HumiMinV = 'W',
    CMD_HumiMinA = 'I',
    CMD_HumiMinS = 'N'
}HumiCMD;

/*
 *@Details: 通信协议
 */
class Protocol{
public:
    Protocol(void);
    ~Protocol(void);
    QByteArray packetMsg(quint8 device, quint8 deviceCmd = PROT_FULL_CMD,
                         quint8 dataLen=PROT_ZERO_LEN,quint8 *data=PROT_FULL_DATA);
    void clearProtocoldata(void);
    void printProtocoldata(void);
    quint8 gainCheckSum(void);
    quint8 calcuCheck(quint8 data, quint8 &crc);

    quint8 m_sendBegin;        //起始标志 以“{”开始
    quint8 m_device;           //设备
    quint8 m_deviceCmd;        //设备命令
    quint8 m_dataLen;		   //数据长度 没有为0
    quint8 *m_data;            //数据	  没有指向空
    quint8 m_sendEnd;          //结束标志 以“}”结束
    quint8 m_checkSum;         //校验和
};

#endif //__PROTOCOL_H__   




